-- lua/core/keymaps.lua - 快捷键映射

vim.g.mapleader = " "
local map = vim.keymap.set
local opts = { noremap = true, silent = true }

-- 基本操作
map("n", "<leader>w", ":w<CR>", opts)  -- 保存文件
map("n", "<leader>q", ":q<CR>", opts)  -- 退出
map("n", "<leader>Q", ":q!<CR>", opts) -- 强制退出
map("n", "<leader>x", ":x<CR>", opts)  -- 保存并退出

-- 窗口操作
map("n", "<C-h>", "<C-w>h", opts)          -- 切换到左边窗口
map("n", "<C-j>", "<C-w>j", opts)          -- 切换到下边窗口
map("n", "<C-k>", "<C-w>k", opts)          -- 切换到上边窗口
map("n", "<C-l>", "<C-w>l", opts)          -- 切换到右边窗口
map("n", "<leader>v", ":vsplit<CR>", opts) -- 垂直分割窗口
map("n", "<leader>s", ":split<CR>", opts)  -- 水平分割窗口
map("n", "<leader>=", "<C-w>=", opts)      -- 平衡窗口大小
map("n", "<leader>_", "<C-w>_", opts)      -- 最大化当前窗口高度
map("n", "<leader>|", "<C-w>|", opts)      -- 最大化当前窗口宽度

-- 缓冲区操作
map("n", "<leader>bn", ":bnext<CR>", opts)     -- 下一个缓冲区
map("n", "<leader>bp", ":bprevious<CR>", opts) -- 上一个缓冲区
map("n", "<leader>bd", ":bdelete<CR>", opts)   -- 删除当前缓冲区

-- 添加快捷键映射
vim.keymap.set({ "n", "v" }, "<C-c>", '"+y', { noremap = true, silent = true })
vim.keymap.set("n", "<C-v>", '"+p', { noremap = true, silent = true })
vim.keymap.set("i", "<C-v>", '<Esc>"+pa', { noremap = true, silent = true })

-- 插件快捷键
map("n", "<leader>ff", ":Telescope find_files<CR>", opts) -- 查找文件
map("n", "<leader>fg", ":Telescope live_grep<CR>", opts)  -- 全局搜索
map("n", "<leader>fb", ":Telescope buffers<CR>", opts)    -- 缓冲区列表
map("n", "<leader>fh", ":Telescope help_tags<CR>", opts)  -- 帮助标签
map("n", "<leader>e", ":Neotree action=show<CR>", opts)   -- 切换文件树
map("n", "<leader>u", ":Neotree action=close<CR>", opts)  -- 切换撤销树
